package forces;

import java.util.Collection;
import java.util.Scanner;
import simulation.Mass;
import util.Vector;


/**
 * This class represents a viscosity force on a mass.
 * 
 */
public class Viscosity extends Force {
    private static final int HALF_REVOLUTION = 180;
    private static final double DEFAULT_SCALE_FACTOR = 0.8;
    private double myScaleFactor;

    /**
     * A default constructor that picks a default value for a proportionality
     * constant.
     */
    public Viscosity () {
        this(DEFAULT_SCALE_FACTOR);
    }

    /**
     * Creates a viscosity force with the specified proportionality constant.
     */
    public Viscosity (double scaleFactor) {
        super();
        myScaleFactor = scaleFactor;
    }

    public Viscosity (Scanner line) {
        this(line.nextDouble());
    }

    /**
     * Implements the abstract update method to calculate and apply
     * the viscosity force on each mass.
     */
    @Override
    public void update (Collection<Mass> masses) {
        for (Mass m : masses) {
            Vector velocity = m.getVelocity();
            setMagnitude(myScaleFactor * velocity.getMagnitude());
            setDirection(velocity.getDirection() + HALF_REVOLUTION);
            m.applyForce(this);
        }
    }

}
